import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:search_people/entrance/route/routes.dart';
import 'package:search_people/page/home/subs/person_detail/index.dart';
import 'package:search_people/page/home/subs/person_detail/models/person_base_model/data.dart';
import 'package:search_people/utils/component/component.dart';
import 'package:search_people/utils/component/page_state/widgets/widgets.dart';
import 'package:search_people/utils/img_util.dart';

import '../../../../../value/topcolors.dart';

class PersonPortraitWidget extends StatelessWidget {
  const PersonPortraitWidget({Key? key, required this.controller})
      : super(key: key);
  final PersonDetailController controller;
  List<PersonBaseModel> _getList() {
    if (controller.state.pTc.index == 0) {
      if (controller.state.fellow.length > 10) {
        return controller.state.fellow.sublist(0, 10);
      }
      return controller.state.fellow;
    }

    if (controller.state.pTc.index == 1) {
      if (controller.state.alumni.length > 10) {
        return controller.state.alumni.sublist(0, 10);
      }
      return controller.state.alumni;
    }
    if (controller.state.colleague.length > 10) {
      return controller.state.colleague.sublist(0, 10);
    }
    return controller.state.colleague;
  }

  @override
  Widget build(BuildContext context) {
    var state = controller.state;

    return Container(
      child: Column(
        children: [
          Container(
            height: 8.r,
            color: TopColors.bg,
          ),
          Container(
            height: 45.r,
            alignment: Alignment.centerLeft,
            padding: EdgeInsets.only(left: 12.r),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Container(
                      height: 15.r,
                      width: 5.r,
                      margin: EdgeInsets.only(right: 10.r),
                      color: TopColors.main_color,
                    ),
                    Text(
                      '人物图谱',
                      style: TextStyle(
                        color: TopColors.black_33,
                        fontSize: 14.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
                IconButton(
                    onPressed: () {
                      controller.state.isShowPortrait =
                          !controller.state.isShowPortrait;
                      controller.update();
                    },
                    icon: Icon(
                      controller.state.isShowPortrait
                          ? Icons.keyboard_arrow_down_outlined
                          : Icons.keyboard_arrow_right_outlined,
                      color: TopColors.main_color,
                    ))
              ],
            ),
          ),
          !state.isShowPortrait
              ? const SizedBox()
              : TPTabBar(tabCtrl: state.pTc, tabTitles: state.pTitles),
          !state.isShowPortrait
              ? const SizedBox()
              : _getList().isEmpty
                  ? EmptyView()
                  : Column(
                      children: _getList()
                          .map(
                            (e) => InkWell(
                              onTap: () {
                                controller.changeLeaderId(e.leaderId);

                                // Get.toNamed(RouterPath.person_detail,
                                //     arguments: e.leaderId);
                              },
                              child: Container(
                                decoration: BoxDecoration(
                                    color: Colors.white,
                                    border: Border(
                                        bottom:
                                            BorderSide(color: TopColors.bg))),
                                padding: EdgeInsets.symmetric(
                                    horizontal: 12.r, vertical: 10.r),
                                child: Row(
                                  children: [
                                    loadAvater(size: 40.r, url: e.image),
                                    SizedBox(
                                      width: 10.r,
                                    ),
                                    Expanded(
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          Text(
                                            e.leaderName ?? '',
                                            style: TextStyle(
                                                color: TopColors.black_33,
                                                fontSize: 12.sp),
                                          ),
                                          Text(
                                            e.currentPosition ?? '',
                                            style: TextStyle(
                                                color: TopColors.black_99,
                                                fontSize: 11.sp),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Icon(
                                      Icons.keyboard_arrow_right_rounded,
                                      color: TopColors.main_color,
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          )
                          .toList(),
                    ),
          _getList().length >= 10
              ? InkWell(
                  onTap: () {
                    Get.toNamed(RouterPath.person_portrait, parameters: {
                      'id': state.leaderId ?? ''
                    }, arguments: [
                      state.fellow,
                      state.alumni,
                      state.colleague
                    ]);
                  },
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 12.r),
                    height: 40.r,
                    color: Colors.white,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '查看更多',
                          style: TextStyle(
                              color: TopColors.black_33, fontSize: 13.sp),
                        ),
                        Icon(
                          Icons.keyboard_arrow_right_rounded,
                          color: TopColors.main_color,
                        ),
                      ],
                    ),
                  ),
                )
              : const SizedBox(),
          Container(
            height: 8.r,
            color: TopColors.bg,
          ),
          Container(
            height: 45.r,
            alignment: Alignment.centerLeft,
            padding: EdgeInsets.only(left: 12.r),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Container(
                      height: 15.r,
                      width: 5.r,
                      margin: EdgeInsets.only(right: 10.r),
                      color: TopColors.main_color,
                    ),
                    Text(
                      '工作动态',
                      style: TextStyle(
                        color: TopColors.black_33,
                        fontSize: 14.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
                IconButton(
                    onPressed: () {
                      controller.state.isShowDynamic =
                          !controller.state.isShowDynamic;
                      controller.update();
                    },
                    icon: Icon(
                      controller.state.isShowDynamic
                          ? Icons.keyboard_arrow_down_outlined
                          : Icons.keyboard_arrow_right_outlined,
                      color: TopColors.main_color,
                    ))
              ],
            ),
          ),
        ],
      ),
    );
  }
}
